import store from './store';
const { globalShortcut, BrowserWindow } = require('electron');
const path = require('path');
// 注册一个'CommandOrControl+X' 快捷键监听器
globalShortcut.register('CommandOrControl+Shift+I', () => openDevTools());
globalShortcut.register('F12', () => openDevTools());
const openDevTools = () => {
  if (!BrowserWindow?.getFocusedWindow()?.webContents?.isDevToolsOpened()) {
    BrowserWindow?.getFocusedWindow()?.webContents?.openDevTools();
  } else {
    BrowserWindow?.getFocusedWindow()?.webContents?.closeDevTools();
  }
};
globalShortcut.register('CommandOrControl+Shift+Space', () => {
  // 继续或者暂停录制
  store.state.mainWindow?.webContents?.send(
    'operateRecorder',
    store.state.recordStatus === 'recording' ? 'pause' : 'continue'
  );
  if (store.state.recordStatus === 'recording') {
    store.state.startTray?.setImage(path.join(__dirname, '../public/pauseTemplate.png'));
  } else {
    store.state.startTray?.setImage(path.join(__dirname, '../public/startTemplate.png'));
  }
  store.setState({
    recordStatus: store.state.recordStatus === 'recording' ? 'pause' : 'recording'
  });
});
globalShortcut.register('CommandOrControl+Shift+S', () => {
  // 停止录制
  store.state.mainWindow?.webContents?.send('operateRecorder', 'stop');
  store.state.mainWindow?.show();
  store.setState({
    recordStatus: 'start'
  });
});

export {};
